
# 计算延迟分布（单位：ms）
high_temp_delay = np.random.uniform(180, 240, 100)  # 高温阶段 (T>0.6)
low_temp_delay = np.random.uniform(60, 100, 100)    # 低温阶段 (T<0.3)

# 绘制对比箱线图
plt.figure(figsize=(5,3))

# 关键修正：获取boxplot返回值并设置patch_artist=True
boxplot = plt.boxplot([high_temp_delay, low_temp_delay], 
                      labels=['高温阶段 (T>0.6)', '低温阶段 (T<0.3)'],
                      patch_artist=True,  # 启用Patch对象
                      widths=0.6)

# 设置箱体颜色
colors = ['#FFBE7A', '#82B0D2']
for patch, color in zip(boxplot['boxes'], colors):
    patch.set_facecolor(color)  # 现在可以正确调用

# 计算延迟降低幅度
median_high = np.median(high_temp_delay)
median_low = np.median(low_temp_delay)
reduction_percent = (median_high - median_low) / median_high * 100

# 标注延迟降低幅度
# plt.text(1.5, 150, f'延迟降低: {reduction_percent:.1f}%', 
#          ha='center', fontsize=12, color='red')

plt.ylabel('计算延迟 (ms)', fontsize=12)
# plt.title('Computing Load Scheduling Effect under Different Temperature Phases', fontsize=14)
plt.grid(axis='y', alpha=0.3)
plt.savefig('computing_load_scheduling.png', bbox_inches='tight')
plt.show()
